from redis import StrictRedis
import logging


class Config(object):
    SECRET_KEY = "ASDFGHJKL"



    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/ReadBook"
    SQLALCHEMY_TRACK_MODIFICATIONS = True

    # 定义类属性
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # session 的储存方式
    SESSION_TYPE = "redis"

    #指定session的储存的对象
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)

    # 设置签名 加密
    SESSION_USE_SIGNER = True

    # 如果为false cookie的保存时间为浏览器关闭 session还是86400*2，如果是True cookie和session保存时间一致
    SESSION_PERMANENT = False

    # 设置session的保存时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2

    # 设置数据库的默认提交
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True



#     面向对象的继承

class DevelopConfig(Config):
    DEBUG = True
    LOG_LEVEL = logging.DEBUG


class ProductConfig(Config):
    DEBUG = False
    LOG_LEVEL = logging.DEBUG


class TestingConfig(Config):
    DEBUG = True


# 使用字典去封装
config = {
    "develop":DevelopConfig,
    "product":ProductConfig,
    "testing":TestingConfig
}